#!/usr/bin/env bash
set -e
echo "init-user-db.sh"

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
    CREATE USER $IMPORT_EXPORT_POSTGRESQL_USER WITH PASSWORD '$IMPORT_EXPORT_POSTGRESQL_PASSWORD';
    CREATE DATABASE $DB_NAME ENCODING 'utf-8';
    GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $IMPORT_EXPORT_POSTGRESQL_USER;
    ALTER USER $IMPORT_EXPORT_POSTGRESQL_USER CREATEDB;
EOSQL